package com.snow.useviewdemo.function.blur;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.os.Bundle;
import android.os.CountDownTimer;

import com.snow.img.ImageUtil;
import com.snow.useviewdemo.R;
import com.snow.useviewdemo.base.BaseActivity;
import com.snow.useviewdemo.databinding.ActivityBlurBinding;

/**
 * author : snowzhao
 * e-mail : zyt@ttsing.com
 * date   : 2020/5/15
 * desc   :高斯模糊效果
 * 第一种方法：ImageBlur 只使用ImageView
 * 另外一种方法:blurkit 适用于任何布局 https://github.com/CameraKit/blurkit-android
 */
public class BlurActivity extends BaseActivity<ActivityBlurBinding> {
    private float movement = 150;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_blur;
    }

    private String imaurl = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1561094715086&di=619ebeb53d8024d675f52f09ff59916f&imgtype=0&src=http%3A%2F%2Fpic22.nipic.com%2F20120626%2F7755371_230304612000_2.jpg";

    @Override
    protected void setViewData(Bundle savedInstanceState) {
        ImageUtil.imageLoad(this, imaurl, mBinding.imageView01);
        ImageUtil.imageLoad(this, imaurl, mBinding.imageView);
        ImageUtil.imageLoad(this, imaurl, mBinding.imageView02);
        new CountDownTimer(2000, 2000) {
            @Override
            public void onTick(long l) {

            }

            @Override
            public void onFinish() {
                ImageBlur.makeBlur(mBinding.imageView, BlurActivity.this);
            }
        }.start();
        mBinding.blurLayout.animate().translationY(movement).setDuration(1500).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                movement = movement > 0 ? -150 : 150;
                mBinding.blurLayout.animate().translationY(movement).setDuration(1500).setListener(this).start();
            }
        }).start();
    }

    @Override
    protected void onStart() {
        super.onStart();
        mBinding.blurLayout.startBlur();
        //设置此方法后，没有毛玻璃效果，显示白色遮罩
//        mBinding.blurLayout.lockView();
    }

    @Override
    protected void onStop() {
        super.onStop();
        mBinding.blurLayout.pauseBlur();
    }
}
